﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NET.MidTestRework.Lib;
using NET.MidTestRework.Lib.Exception;

namespace NET.MidTestRework.Main
{
    class Program
    {
        static void Main(string[] args)
        {
            Cryptography obj = new Cryptography();
            //string firstString = "yoga";
            //string secondString = "brjd";
            //int stepPerform1 = 6;

            //try
            //{
            //    string resultAfterEncrypt = obj.Encrypt(firstString.ToUpper(), stepPerform1);
            //    string resultAfterDecrypt = obj.Decrypt(secondString.ToUpper(), stepPerform1);
            //    Console.WriteLine("Encrypt word 'yoga' : {0}", resultAfterEncrypt);
            //    Console.WriteLine("Decrypt word 'brjd' : {0}", resultAfterDecrypt);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(""+ex.Message);
            //}

            Console.WriteLine("1. Encrypt : Type [Encrypt] [Your Word] [Step Performed]");
            Console.WriteLine("2. Decrypt : Type [Decrypt] [Your Word] [Step Performed]");
            string commandLine;
            string command = string.Empty;
            while (command != "Exit")
            {
                commandLine = System.Console.ReadLine();
                string[] commands = commandLine.Split(' ');
                command = commands[0];             
                switch (command)
                {
                    case "Encrypt":
                        try
                        {
                            string input = commands[1];
                            string stepFormed = commands[2];
                            string resultAfterEncrypt = obj.Encrypt(input.ToUpper(), Int32.Parse(stepFormed));
                            Console.WriteLine("{0}", resultAfterEncrypt);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("" + ex.Message);
                        }
                        break;
                    case "Decrypt":
                        try
                        {
                            string input = commands[1];
                            string stepFormed = commands[2];
                            string resultAfterDecrypt = obj.Decrypt(input.ToUpper(), Int32.Parse(stepFormed));
                            Console.WriteLine("{0}", resultAfterDecrypt);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("" + ex.Message);
                        }
                        break;
                    case "Exit":
                        Console.WriteLine("Exit the application.");
                        break;
                    default:
                        Console.WriteLine("Invalid command.");
                        break;
                }
            }
        }
    }
}
